﻿<%@ WebHandler Language="C#" Class="uploadify" %>

using System;
using System.Web;
using System.IO;
using System.Drawing;
public class uploadify : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        HttpPostedFile oFile = context.Request.Files["Filedata"];
        if (oFile != null)
        {
            int member_id = Axis.Web.Administrator.Global.CSecurity.MEMBER_ID;
            string sDirectory = context.Server.MapPath("~/uploads/Member/" + member_id + "/");

            if (!Directory.Exists(sDirectory))
                Directory.CreateDirectory(sDirectory);
            string fileType = "png";
            string fileName = "Avatar_" + member_id + "." + fileType;
            int fileLenght = oFile.ContentLength;
            oFile.SaveAs(Path.Combine(sDirectory, fileName));
            string filePath = "/uploads/Member/" + member_id + "/" + fileName;
            string ret = string.Format("{{ IsSuccessfull: true, FileType: '{0}', FileName: '{1}', FilePath:'{2}', FileSize: '{3}' }}", fileType, fileName, filePath, fileLenght);
            context.Response.Write(ret);
        }
        else
        {
            context.Response.Write("{{ IsSuccessfull: false }}");
        }
    }

    public bool IsReusable
    {
        get { return false; }
    }
}